package com.yzg.simple.nio;


import java.io.FileInputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

/**
 * @ClassName ChannelInput
 * @Description TODO
 * @Authoe weiyan
 * @Date 2019/12/20 14:33
 * @Version 1.0
 *
   再所有的Channel 中都是 抽象类， 统一的实现类就是 *Impl 如： FileChannelImpl
 * Channel  -- FileChannel 渠道的说明  配合ByteBuffer 使用
 **/
public class ChannelInput {

    public static void main(String[] args) throws Exception {
        FileInputStream stream = new FileInputStream("d://hello.txt");

        FileChannel channel = stream.getChannel();
        ByteBuffer allocate = ByteBuffer.allocate((int) channel.size());

        channel.read(allocate);

        System.out.println(new String(allocate.array()));

        stream.close();
    }

}